import storage from '@/utils/cookie'

const ACCESS_TOKEN_KEY = 'access_token'
const REFRESH_TOKEN_KEY = 'refresh_token'

export async function saveToken (token) {
  await storage.set(ACCESS_TOKEN_KEY, token)
}
export async function removeToken () {
  await storage.remove(ACCESS_TOKEN_KEY)
  await storage.remove(REFRESH_TOKEN_KEY)
}

export function getToken () {
  return storage.get(ACCESS_TOKEN_KEY) || {}
}

function getTokenType () {
  const token = getToken()
  return token.token_type || ''
}

export function getAccessToken () {
  const token = getToken()
  return getTokenType() + ' ' + (token.access_token || '')
}
